<template>
  <div class="">
    <div class="">
      <TableCompEle class="m-t" ref="multipleTable" height="50vh" :tableData="tableData" :tableConfig="tableConfig" :tableAction="tableAction"
        :isSelect="false" :isIndex="true" :isShowPage="true" :queryParams="queryParams" @getPagination="getList"
        ></TableCompEle>
    </div>
    <AddComp ref="addRef" @close="getList" />
    <AddSelfComp ref="addSelfRef" @close="getList" />
  </div>
</template>

<script>
import {
  getAppointmentList
} from '@/api/yqgx/appointment'
import AddComp from '@/views/Information/serviceManage/makeManage/common/add.vue'
import AddSelfComp from '@/views/Information/evaluatePge/selfEvaluation/common/add.vue'
export default {
  components: { AddComp, AddSelfComp },
  computed: {
    userAuth() {
      return localStorage.getItem('userInfo')
        ? JSON.parse(localStorage.getItem('userInfo'))[0]
        : {
          "userId": 1299,
          "userName": "admin",
          "userRealName": "管理员",
          "userEmail": null,
          "deptName": null,
          "createBy": "admin",
          "createTime": "2024-01-02 21:39:11",
          "departmentName": "",
          "departmentId": null,
          "selectFlag": true,
          "userHeadPath": null,
          "userPhone": 18702348729,
          "enableFlag": "y",
          "roleName": "平台管理员"
        }
    }
  },
  data() {
    return {
      activeName: 'all',
      queryParams: {
        total: 3,
        currentPage: 1,
        pageSize: 10
      },
      tableData: [
        // {
        //   title: '中国散裂中子源',
        //   need: '模拟的实验环境',
        //   name: '探究物质微观结构的“超级显微镜”',
        //   property: '科研性质',
        //   startTime: '2023-04-01',
        //   endTime: '2024-01-31',
        //   applyName: '管理员',
        //   applyPhone: '010-23543221',
        //   companyName: '广东省科学技术厅',
        //   answer: '受理'
        // },
        // {
        //   title: '全超导托卡马克核聚变实验装置（EAST)',
        //   need: '运行磁约束核聚变',
        //   name: '基于湍动电流自主调节的内部温度垒的深入研究',
        //   property: '科研性质',
        //   startTime: '2023-07-01',
        //   endTime: '2025-01-31',
        //   applyName: '管理员',
        //   applyPhone: '13823427618',
        //   companyName: '中国科学院合肥物质科学研究院',
        //   answer: '受理'
        // },
        // {
        //   title: '北京正负电子对撞机',
        //   need: '探测器电性能测试',
        //   name: '适配BEPCII高计数率运行',
        //   property: '非科研性质',
        //   startTime: '2023-12-01',
        //   endTime: '2024-06-28',
        //   applyName: '管理员',
        //   applyPhone: '010-3459483',
        //   companyName: '中国科学院高能物理研究所',
        //   answer: '不受理'
        // }
      ],
      tableConfig: [
        {
          prop: 'title',
          label: '共享资源名称'
        },
        {
          prop: 'need',
          label: '共享使用需求'
        },
        {
          prop: 'name',
          label: '课题(任务)名称'
        },
        {
          prop: 'property',
          label: '课题(任务)性质'
        },
        {
          prop: 'startTime',
          label: '预约起始时间'
        },
        {
          prop: 'endTime',
          label: '预约结束时间'
        }
      ],
      tableAction: {
        align: () => 'center',
        width: () => String(100),
        operations: [
          {
            label: '查看',
            isLink: true,
            type: 'primary',
            method: row => {
              this.$refs.addRef.show({
                title: '查看服务预约信息',
                isLook: 'look',
                data: row
              })
            }
          },
          {
            label: '评价',
            isLink: true,
            type: 'primary',
            method: (row) => {
              this.$refs.addSelfRef.show({
                title: '评价',
                evaluateType: '预约',
                data: {
                  evaluateTime: this.getNowFormatDate(),
                  evaluator: this.userAuth.userRealName,
                  evaluate: 5,
                  ...row
                }
              })
            }
          }
        ]
      }
    }
  },
  created() {
    this.getList()
  },
  methods: {
    getList() {
      getAppointmentList().then((res) => {
        this.tableData = res.data.filter(item => item.answer)
      })
    },
    getNowFormatDate() {
      let date = new Date(),
        year = date.getFullYear(), //获取完整的年份(4位)
        month = date.getMonth() + 1, //获取当前月份(0-11,0代表1月)
        strDate = date.getDate() // 获取当前日(1-31)
      if (month < 10) month = `0${month}` // 如果月份是个位数，在前面补0
      if (strDate < 10) strDate = `0${strDate}` // 如果日是个位数，在前面补0

      return `${year}-${month}-${strDate}`
    }
  }
}
</script>

<style lang="less" scoped>
</style>